<template>
    <view class="container">
        <!-- 用户信息区域 -->
        <view class="user-info-section">
            <!-- 退出登录按钮 -->
            <view class="logout-btn" @click="logout">
                <text class="logout-text">退出登录</text>
            </view>

            <!-- 用户头像和姓名 -->
            <view class="user-profile">
                <image class="avatar" src="/static/logo.png" mode="aspectFill"></image>
                <text class="user-name">{{ userInfo.name }}</text>
            </view>

            <!-- 用户基本信息 -->
            <view class="user-stats">
                <view class="stat-item">
                    <text class="stat-value">{{ userInfo.employeeId }}</text>
                    <text class="stat-label">工号</text>
                </view>
                <view class="stat-item">
                    <text class="stat-value">{{ userInfo.points }}</text>
                    <text class="stat-label">积分</text>
                </view>
                <view class="stat-item">
                    <text class="stat-value">{{ userInfo.position }}</text>
                    <text class="stat-label">岗位名称</text>
                </view>
                <view class="stat-item">
                    <text class="stat-value">{{ userInfo.level }}</text>
                    <text class="stat-label">岗位职级</text>
                </view>
            </view>
        </view>

        <!-- 菜单列表 -->
        <view class="menu-section">
            <uni-list>
                <uni-list-item v-for="item in menuItems" :key="item.id" :title="item.title" :showArrow="true"
                    :clickable="true" @click="handleMenuClick(item)" class="menu-item">
                    <template #header>
                        <view class="menu-icon">
                            <text class="iconfont" :class="item.icon"> </text>
                        </view>
                    </template>
                </uni-list-item>
            </uni-list>
        </view>


    </view>
</template>

<script setup>
import { ref } from 'vue'

// 用户信息
const userInfo = ref({
    name: '张三',
    employeeId: '001',
    points: '1000',
    position: '工程师',
    level: '中级'
})

// 菜单项配置
const menuItems = ref([
    { id: 1, title: '基本信息', icon: 'icon-geren', path: '/pages/user/children/basic-info' },
    { id: 2, title: '时间信息', icon: 'icon-rili', path: '/pages/user/children/time-info' },
    { id: 3, title: '证件信息', icon: 'icon-shenfengzheng', path: '/pages/user/children/certificate-info' },
    { id: 4, title: '工作年限', icon: 'icon-gongzuotai', path: '/pages/user/children/work-years' },
    { id: 5, title: '工资明细', icon: 'icon-wodegongzi', path: '/pages/user/children/salary-details' },
    { id: 6, title: '学习记录', icon: 'icon-jilu', path: '/pages/user/children/learning-records' },
    { id: 7, title: '密码修改', icon: 'icon-mima', path: '/pages/user/children/change-password' }
])

// 处理菜单点击
function handleMenuClick(item) {
    if (item.path) {
        uni.navigateTo({
            url: item.path
        })
    } else {
        uni.showToast({
            title: `点击了${item.title}`,
            icon: 'none'
        })
    }
}

// 退出登录
function logout() {
    uni.showModal({
        title: '提示',
        content: '确定要退出登录吗？',
        success: (res) => {
            if (res.confirm) {
                uni.showToast({
                    title: '已退出登录',
                    icon: 'success'
                })
                // 这里可以添加退出登录的逻辑
            }
        }
    })
}


</script>

<style>
.container {
    min-height: 100vh;
    background-color: #f5f5f5;
    position: relative;
}

.user-info-section {
    background: #fff;
    padding: 40rpx 30rpx;
    margin-bottom: 20rpx;
    position: relative;
}

.logout-btn {
    position: absolute;
    top: 40rpx;
    right: 30rpx;
    z-index: 10;
}

.logout-text {
    color: #666;
    font-size: 28rpx;
}

.user-profile {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 40rpx;
}

.avatar {
    width: 120rpx;
    height: 120rpx;
    border-radius: 50%;
    margin-bottom: 20rpx;
}

.user-name {
    font-size: 36rpx;
    font-weight: bold;
    color: #333;
}

.user-stats {
    display: flex;
    justify-content: space-around;
    padding: 0 20rpx;
}

.stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.stat-value {
    font-size: 32rpx;
    font-weight: bold;
    color: #333;
    margin-bottom: 8rpx;
}

.stat-label {
    font-size: 24rpx;
    color: #666;
}

.menu-section {
    background: #fff;
}

.menu-item {
    border-bottom: 1rpx solid #f0f0f0;
}

.menu-item:last-child {
    border-bottom: none;
}

.menu-icon {
    width: 40rpx;
    height: 40rpx;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 20rpx;
}

.menu-icon .iconfont {
    font-size: 32rpx;
    color: #333;
}
</style>
